<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=10">
  <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <title>火星捕手-收银端</title>
  <link rel="shortcut icon" href="http://hxypic.oss-cn-hangzhou.aliyuncs.com/bitbug_favicon.ico">
  <link rel="stylesheet" href="static/css/reset.css">
  <!-- <link rel="stylesheet" href="//at.alicdn.com/t/font_360610_xsreqc8v2tltbj4i.css"> -->
  <link rel="stylesheet" href="//at.alicdn.com/t/font_360610_ma56bkj65o0tfbt9.css">
  <!-- <link rel="stylesheet" href="//at.alicdn.com/t/font_790077_bhizrfvaonf.css"> -->
  <link rel="stylesheet" href="//at.alicdn.com/t/font_790077_kq7pqg2wykm.css">
  <!-- <link rel="stylesheet" href="//at.alicdn.com/t/font_496349_eb7p8idquhqcl3di.css"> -->
  <script src="static/js/jQuery-2.1.4.min.js"></script>
  <script src="static/js/jQuery.speech.min.js"></script>
  <script src="static/js/jquery.jqprint-0.3.js"></script>
  <script src="static/js/jquery-migrate-1.2.1.min.js"></script>
  <script src="static/js/qrcode.js"></script>
  <!-- <script src="static/js/flexible.js"></script> -->
  <script src="static/js/Base64.js"></script>
  <!-- <script src="static/js/md5.js"></script> -->
  <script src="static/js/es6-promise.auto.min.js"></script>
  <script src="static/js/sockjs-1.1.1.js"></script>
  <script src="static/js/stomp.js"></script>

  <!-- 壳子js -->
  <script src="static/js/qwebchannel.js"></script>
  <!-- <script>
    window.socketComplete = function () {
      bridge.PrintTcpFail.connect(function () {
        alert('厨房打印故障,请联系厨房核实单据。');
      });
    }
  </script> -->
  <script src="static/js/wsock.js"></script>

  <script type="text/javascript">
    //与客程序建立连接成功后执行
    window.socketComplete = function () {
      if (bridge) {
        console.log(bridge)
        //如果是本地打印机可以在这里调用一次open
        bridge.Open("", function (returnvalue) {
          // console.log("open return " + returnvalue);
        });

        //绑定网络打印机打印结果事件PrintTcpResult
        bridge.PrintTcpResult.connect(function (str) {
          console.log("Received PrintTcpResult from qt: " + str);
          if (str != "Success") {
            alert("厨房打印失败，请联系厨房核对单据。");
          }
        });

        //绑定USB打印机打印结果事件PrintResult
        bridge.PrintResult.connect(function (str) {
          console.log("Received PrintResult from qt: " + str);
          if (str != "Success") {
            alert("小票打印失败，请检查小票打印机是否正确连接");
          }
        });
      }
    }

  </script>

  <script src="static/js/gbk.js"></script>
  <script src="static/js/gbk2.js"></script>
  <script src="static/js/encodeToGb2312.min.js"></script>

</head>

<body>
  <div id="app"></div>
</body>
<script type="text/javascript">
  // new QWebChannel(qt.webChannelTransport, function(channel) {
  //     window.bridge = channel.objects.bridge;
  //     //Web connect the Qt signal, then Qt can call "output" function
  //     // bridge.SigSendMessageToJS.connect(function(str) {  
  //     //     alert("Received string from Qt: " + str);  
  //     // }); 
  //     console.log(bridge);
  //     bridge.PrintTcpFail.connect(function(str) {
  //         alert("没有找到网口打印机，请检查！");  
  //     }); 
  // })


  // if (bridge) {
  //         bridge.Open("",function(returnvalue){
  //             console.log(returnvalue);
  //             // if(returnvalue>0){

  //             // }else{
  //             //     alert('没有找到打印机');
  //             // }
  //         });
  //         // bridge.PrintCmd(printID, printData.join(","));
  //         // bridge.Close(printID);
  // }
//
function string2Bytes(str) {
      var bytes = new Array();
			var len, c;
			len = str.length;
			for(var i = 0; i < len; i++) {
				c = str.charCodeAt(i);
				if(c >= 0x010000 && c <= 0x10FFFF) {
					bytes.push(((c >> 18) & 0x07) | 0xF0);
					bytes.push(((c >> 12) & 0x3F) | 0x80);
					bytes.push(((c >> 6) & 0x3F) | 0x80);
					bytes.push((c & 0x3F) | 0x80);
				} else if(c >= 0x000800 && c <= 0x00FFFF) {
					bytes.push(((c >> 12) & 0x0F) | 0xE0);
					bytes.push(((c >> 6) & 0x3F) | 0x80);
					bytes.push((c & 0x3F) | 0x80);
				} else if(c >= 0x000080 && c <= 0x0007FF) {
					bytes.push(((c >> 6) & 0x1F) | 0xC0);
					bytes.push((c & 0x3F) | 0x80);
				} else {
					bytes.push(c & 0xFF);
				}
			}
			return bytes;
  }
//

  function print_(printID, printData) {
    // alert("printID:"+printID)
    // console.log("printID:"+printID,"printData:"+printData);
    // if (bridge) {
    // bridge.Open(printID, function (returnvalue) {
    //   console.log(returnvalue)
    //   // if(returnvalue>0){

    //   // }else{
    //   //     alert('没有找到打印机');
    //   // }
    // });
    // }
    console.log(printID)
    bridge.PrintCmd(printID, printData.join(","));
    //test start
    //let arr = [];
    //arr = arr.concat([27]);
    //encodeToGb2312("GAP 2 mm,0 mm  \r\n");
    //arr = arr.concat(GBK.encode('SIZE 30 mm,20 mm\r\n'));
    //arr = arr.concat(GBK.encode('GAP 2 mm,0 mm\r\n'));
    //arr = arr.concat(GBK.encode("CLS \r\n"));
    //arr = arr.concat(GBK.encode('TEXT 50,50,"TSS24.BF2",0,1,1,"你好"\r\n'));

    //arr = arr.concat(GBK.encode('PRINT 1,1\r\n'));
    //let testData = arr;
    //console.log(testData);
    //bridge.PrintCmd(printID, testData.join(","));
    //test end
     //bridge.Close(printID);
    // }
    // try{
    // }catch(err){
    //     alert('请使用收银客户端进行打印1');
    // };

  };

  function printForTag(printID, printData) {
    
    //console.log(printID)
    //test start
    //let arr = [];
    //arr = arr.concat(GBK.encode('SIZE 30 mm,20 mm\r\n'));
    //arr = arr.concat(GBK.encode('GAP 2 mm,0 mm\r\n'));
    //arr = arr.concat(GBK.encode("CLS \r\n"));
    //arr = arr.concat(GBK.encode('TEXT 50,50,"TSS24.BF2",0,1,1,"你好"\r\n'));
    //arr = arr.concat(GBK.encode('TEXT 50,50,"TSS24.BF2",0,1,1,'));
    //arr = arr.concat(GBK.encode('你好呀'));
    //arr = arr.concat(GBK.encode('\r\n'));
    //arr = arr.concat(GBK.encode('PRINT 1,1\r\n'));
    //let testData = arr;
    //console.log(testData);
    bridge.PrintCmd(printID, printData.join(","));
    //test end
  };



  function printTcp_(printIP_Port, printData) {
    if (bridge) {
      bridge.PrintTcp(printIP_Port.ip, printIP_Port.port, printData.join(","));
      //
      // bridge.PrintTcpFail.connect(function () { 
      //     window.location.reload();
      //     alert('厨房打印故障,请联系厨房核实单据。');
      // });
      // bridge.Close();
      //
    }
    // try{
    // }catch(err){
    //     alert('请使用收银客户端进行打印2');
    // };

  };

</script>

</html>
